<template>
  <div>
    <div class="list" v-for="item in lists" :key="item.id">
      <div>{{ item.name + "￥" + item.price }}</div>
      <div class="tap">
        <div class="step">
          <span @click="sub(item.id)">-</span>
          <input
            :value="item.num"
            @blur="changeNum(item.id, $event)"
            type="text"
          />
          <span @click="add(item.id)">+</span>
        </div>
        <div @click="delTap(item.id)">X</div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    lists: Array
  },
  data() {
    return {};
  },
  methods: {
    delTap(id) {
      this.$emit("delCart", id);
    },
    changeNum(id, event) {
      this.$emit("change-num", {
        id: id,
        num: event.target.value,
        type: "change"
      });
    },
    sub(id) {
      this.$emit("change-num", {
        id: id,
        type: "sub"
      });
    },
    add(id) {
      this.$emit("change-num", {
        id: id,
        type: "add"
      });
    }
  }
};
</script>

<style scoped>
.list {
  display: flex;
  justify-content: space-around;
  line-height: 36px;
}

.step input {
  width: 30px;
  margin: 0 5px;
  overflow-x: auto;
  text-align: center;
}

.step span {
  font-size: 18px;
  font-weight: 600;
}

.tap {
  display: flex;
}

.step {
  margin-right: 20px;
}
</style>
